﻿//新增模板详细信息
InsertNormal_TemplateList = function (pId) {

    Ext.define("Normal_TemplateTypeModel", {
        extend: 'Ext.data.Model',
        proxy: {
            actionMethods: 'post',
            type: 'ajax',
            url: '/manager/Normal_TemplateType/List/m',
            reader: {
                type: 'json',
                root: 'root',
                totalProperty: 'totalPorperty'
            }
        },

        fields: ['TemplateType', 'TemplateTypeName']
    });

    //模板
    var Normal_TemplateTypeDs = Ext.create('Ext.data.Store', {
        autoLoad: true,
        pageSize: 1000,
        model: 'Normal_TemplateTypeModel'
    });
    var InsertNormal_TemplateListForm = Ext.create("Ext.form.Panel", {
        width: 360,
        height: 450,
        plain: true,
        autoScroll: true,
        layout: "anchor",
        defaultType: "textfield",
        labelWidth: 55,
        baseCls: "x-plain",
        defaults: { labelAlign: 'right', anchor: '90%', msgTarget: "side" },
        buttonAlign: "center",
        bodyStyle: "padding:0 0 0 0",
        items: [{
            name: "TemplateId",
            fieldLabel: "<font color='red'>*</font>模板Id",
            allowBlank: false,
            blankText: "模板Id不能为空",
            regex: /^[\d]{0,10}$/,
            readOnly: true,
            value: pId,
            regexText: "请填写0～10个数字"
        }, {
            name: "ModuleType",
            fieldLabel: "<font color='red'>*</font>模板页类型",
            allowBlank: false,
            xtype: "combo",
            anchor: '90%',
            store: Normal_TemplateTypeDs,
            displayField: 'TemplateTypeName',
            queryMode: 'TemplateTypeName',
            valueField: 'TemplateType'
         }, {
            name: "TemplateName",
            fieldLabel: "<font color='red'>*</font>模板页地址",
            allowBlank: false,
            blankText: "模板页名称不能为空"
        }, {
            name: "TemplateTitle",
            fieldLabel: "<font color='red'>*</font>模板页名称",
            allowBlank: false,
            blankText: "模板页名称不能为空"
        }, {
            name: "Enabled",
            fieldLabel: "是否启用",
            xtype: "combo",
            //传入后台真实值value field /value
            emptyText: '请选择',
            triggerAction: 'query',
            hiddenName: "M_IsSystem",
            mode: "local",
            displayField: "show",
            valueField: "value",
            triggerAction: "all",
            value: true,
            store: Ext.create('Ext.data.Store', {
                fields: ['show', 'value'],
                data: [
			                    { "show": "是", "value": true },
			                    { "show": "否", "value": false }
			                ]
            })
        }, {
            name: "IsDefault",
            fieldLabel: "是否默认",
            xtype: "combo",
            //传入后台真实值value field /value
            emptyText: '请选择',
            mode: "local",
            displayField: "show",
            valueField: "value",
            triggerAction: "all",
            value: true,
            store: Ext.create('Ext.data.Store', {
                fields: ['show', 'value'],
                data: [
			                    { "show": "是", "value": true },
			                    { "show": "否", "value": false }
			                ]
            })
        }
			]
    });


    var InsertNormal_TemplateListWin = Ext.create('Ext.window.Window', {
        title: "新增模板详细信息",
        width: 400,
        height: 450,
        plain: true,
        layout: "fit",
        //不可以随意改变大小
        resizable: false,
        //是否可以拖动
        //draggable:false,
        defaultType: "textfield",
        collapsible: true, //允许缩放条
        closeAction: 'hide',
        closable: true,
        //弹出模态窗体
        modal: 'true',
        buttonAlign: "center",
        bodyStyle: "padding:10px 0 0 15px",
        items: [InsertNormal_TemplateListForm],

        buttons: [{
            text: "保存信息",
            minWidth: 70,
            handler: function () {
                //alert(InsertNormal_TemplateListForm.getForm().isValid())
                if (InsertNormal_TemplateListForm.getForm().isValid()) {
                    //弹出效果 Ext.MessageBox.alert("asdf");
                    Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                    setTimeout(function () { }, 1000);
                    InsertNormal_TemplateListForm.form.submit({
                        url: "/manager/Normal_TemplateList/Insert/",
                        method: "POST",
                        success: function (form, action) {
                            //成功后
                            Ext.MessageBox.hide();
                            var flag = action.result.success;
                            if (flag == "true") {
                                Normal_TemplateListStore.loadPage(1);
                                Ext.helper.msg("恭喜", "新增成功!");
                                InsertNormal_TemplateListWin.hide();
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.MessageBox.alert("新增失败!", message);
                                }
                                else {
                                    Ext.MessageBox.alert("提示!", "新增失败!");
                                    InsertNormal_TemplateListWin.hide();
                                }

                            }
                        },
                        failure: function (form, action) {
                            Ext.MessageBox.alert("提示!", "新增失败!");
                        }
                    });
                }
            }
        }, {
            text: "重置",
            minWidth: 70,
            qtip: "重置数据",
            handler: function () {
                //加载表单数据
                InsertNormal_TemplateListForm.getForm().reset();
            }
        }, {
            text: "取 消",
            minWidth: 70,
            handler: function () {
                InsertNormal_TemplateListWin.hide();
            }
        }]

    });

    InsertNormal_TemplateListWin.show();
}
